package demo1;

import demo2.Cell;

public class CellMethod {

    //创建顺时针旋转
    public static void rotateRightAction(){
        Statement.currentOne.rotateRight();
        //判断是否越界或者是否重合
        if(JudgeMethod.outOfBounds() || JudgeMethod.coincide()){
            Statement.currentOne.rotateLeft();
        }
    }
    //创建逆时针旋转
    public static void rotateLeftAction(){
        Statement.currentOne.rotateLeft();
        //判断是否越界或者是否重合
        if(JudgeMethod.outOfBounds() || JudgeMethod.coincide()){
            Statement.currentOne.rotateRight();
        }
    }

    //瞬间下落
    public static void handDropAction(){
        while(true){
            //判断四方格能否下落
            if(JudgeMethod.canDrop()){
                Statement.currentOne.softDrop();
            }else{
                break;
            }
        }
        //嵌入到墙中
        landToWall();
        //判断能否消行
        JudgeMethod.destroyLine();
        //判断游戏是否结束
        if(JudgeMethod.isGameOver()){

            Statement.game_state = Statement.GAMEOVER;
        }else{
            //游戏没有结束，继续生成新的四方格
            Statement.currentOne = Statement.nextOne;
            Statement.nextOne = Tetromino.randomOne();
        }
    }

    //按键一次四方格下落一格
    public static void sortDropAction(){
        //判断能否下落
        JudgeMethod.judge();
    }

    //四方格嵌入到墙中
    public static void landToWall() {
        Cell[] cells = Statement.currentOne.cells;
        for (Cell cell : cells) {
            int row = cell.getRow();
            int col = cell.getCol();
            Statement.wall[row][col] = cell;
        }
    }


    //按键一次四方格左移一次
    public static void moveLeftAction(){
        Statement.currentOne.moveLeft();
        //判断是否越界或者四方格是否重合
        if(JudgeMethod.outOfBounds() || JudgeMethod.coincide()){
            Statement.currentOne.moveRight();
        }
    }
    //按键一次四方格右移一次
    public static void moveRightAction(){
        Statement.currentOne.moveRight();
        //判断是否越界
        if(JudgeMethod.outOfBounds() || JudgeMethod.coincide()){
            Statement.currentOne.moveLeft();
        }
    }

}

